/**
 * 
 */
package com.and.xmppsdk.adapter;

import java.util.List;

import org.drl.xmpp.TSession;
import org.drl.xmpp.util.StringUtils2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.and.xmppsdk.R;

/**
 * @author hljdrl@gmail.com
 * 
 */
public class SessionArrayAdapter extends ArrayAdapter<TSession> {
	private LayoutInflater mInflater;

	public SessionArrayAdapter(Context context, List<TSession> lst) {
		super(context, 0, lst);
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (view == null) {
			view = mInflater.inflate(R.layout.adapter_sessionitem, parent,
					false);
		}
		TSession mCm = getItem(position);
		setupSessionViewItem(view, mCm);
		return view;
	}

	public static final void setupSessionViewItem(View view, TSession mCm) {
		if (view == null || mCm == null) {
			return;
		}
		TextView name1 = (TextView) view.findViewById(R.id.name);
		TextView name2 = (TextView) view.findViewById(R.id.name2);
		TextView status = (TextView) view.findViewById(R.id.status);
		name1.setText(StringUtils2.parseName(mCm.getSessionName()));

//		if (StringHelper.isText(mCm.getSessionJid())) {
//			name2.setText(mCm.getSessionJid());
//		}
		status.setText(mCm.getBody());
	}

}
